<template>
  <div class="app-container">
    <div style="padding:20px;">
      <el-form :inline="true" class="search-form">
        <el-row style="display: flex; flex-wrap: wrap">
          <el-col :span="20">
            <el-form-item label="活动名称：">
              <el-input
                v-model="searchForm.activity_name"
                placeholder="请输入名称"
                :maxlength="20"
                show-word-limit

              />
            </el-form-item>
            <el-form-item label="状态：">
              <el-select v-model="searchForm.status" placeholder="请选择状态">
                <el-option
                  v-for="item in [
                    { name: '结束', id: '-1' },
                    { name: '已开始', id: '1' },
                    { name: '已关闭', id: '2' },
                    { name: '进行中', id: '3' },
                  ]"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="text-align: right">
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="getListWay"
              >查询</el-button>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-refresh"
                @click="resetting"
              >重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-divider></el-divider>
    <div class="marginTop">
      <div class="marginBottom">
        <el-row :gutter="20">
          <el-col>
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              size="small"
              @click="addWay"
            >添加111活动</el-button>
          </el-col>
        </el-row>
      </div>
      <el-row :gutter="20">
        <el-col>
          <el-table
            v-loading="loading"
            :header-cell-style="{
              'background-color': '#f3f8fe',
              color: '#606266',
              height: '50px',
            }"
            highlight-current-row
            :data="dataList"
            style="width: 100%"
          >
            <el-table-column align="center" prop="id" label="ID" />
            <el-table-column
              align="center"
              prop="activity_name"
              label="活动名称"
            />
            <el-table-column align="center" prop="start_time" label="开始时间" />
            <el-table-column align="center" prop="end_time" label="结束时间" />
            <!-- <el-table-column align="center" prop="status" label="商品">
              <template slot-scope="scope">
                <el-button @click="lookGoodsWay(scope.row)" type="text"
                  >查看活动商品</el-button
                >
              </template>
            </el-table-column> -->
            <el-table-column align="center" prop="status" label="状态">
              <template slot-scope="scope">
                <span
                  v-if="scope.row.status == -1" style="color:#ff4949;"
                >活动结束</span>
                <span
                  v-if="scope.row.status == 1" style="color:#13ce66;"
                >已开启</span>
                <span
                  v-if="scope.row.status == 2" style="color:#81b337;"
                >已关闭</span>
                <span
                  v-if="scope.row.status == 3" style="color:#13ce66;"
                >进行中</span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              fixed="right"
              width="200"
              prop="address"
              label="操作"
            >
              <template slot-scope="scope">
                <el-button
                style="margin: 5px"
                  v-if="scope.row.status == 1 || scope.row.status == 3"
                  type="warning"
                  size="mini"
                  @click="saveStatus(scope.row)"
                >
                  关闭活动
                </el-button>
                <el-button
                disabled
                  style="margin: 5px"
                  v-if="scope.row.status == -1"
                  type="danger"
                  size="mini"
                >
                  活动结束
                </el-button>
                <el-button
                style="margin: 5px"
                  v-if="scope.row.status == 2"
                  type="success"
                  size="mini"
                  @click="saveStatus(scope.row)"
                >
                  开启活动
                </el-button>

                <el-button
                  style="margin: 5px"
                  type="primary"
                  size="mini"
                  @click="emitWay(scope.row)"
                >
                  修改
                </el-button>
                <el-popconfirm
                  title="这是一段内容确定删除吗？"
                  @confirm="delWay(scope.row)"
                >
                  <el-button slot="reference" style="margin: 5px" :disabled="scope.row.status == 1 || scope.row.status == 3" type="danger" size="mini">
                    删除
                  </el-button>
                </el-popconfirm>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row class="marginTop" style="text-align: right">
        <el-pagination
          :current-page="searchForm.page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="searchForm.page.count"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-row>
    </div>

    <!-- 添加或者编辑活动 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="activityId?'修改活动':'添加活动'"
      :visible.sync="dialogVisible"
      width="800px"
      @close="handleClose"
    >
      <el-row v-loading="submitLoading" :gutter="20">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="110px"
          class="demo-ruleForm"
        >
          <el-col :span="24" class="splitTitle">
            <div class="split">活动信息</div>
          </el-col>
          <el-col :span="11">
            <el-form-item label="活动名称" prop="activity_name">
              <el-input
                v-model="ruleForm.activity_name"
                placeholder="请输入活动名称"
                :maxlength="20"
                show-word-limit

              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="ruleForm.status" size="mini">
                <el-radio :label="1">开启</el-radio>
                <el-radio :label="2">关闭</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="时间段" prop="domeTime">
              <el-date-picker
                v-model="domeTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="22">
          <el-form-item label="活动海报" prop="image">
            <logo-upload
              :single-file="poster"
              :show-file-list="false"
              accept="image/jpeg, image/png"
              @uploadCallback="posterBack"
            />
          </el-form-item>
           </el-col>
          <el-col :span="22">
            <el-form-item label="活动说明" prop="explain">
              <el-input placeholder="请输入活动说明" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }"
                v-model="ruleForm.explain" maxlength="200" show-word-limit></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" class="splitTitle">
            <div class="split">活动设置</div>
          </el-col>
          <el-col :span="24">
            <el-form-item label="默认赠送比例" prop="default_gift_ratio">
              <div style="display: flex;align-items: center;">
                <el-input
                style="width: 160px;"
                  v-model="ruleForm.default_gift_ratio"
                  placeholder="请输入赠送比例"
                  type="number"
                  :max="100"
                  onkeyup="value =value.replace(/[^0-9.]/g, '')"
                />
                <span style="font-size: 14px;width: 500px;margin-left: 10px;">%（说明：此处是赠送对应比例的积分，只需输入≥1的整数即可）</span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="赠送节点" prop="giveaway_node">
              <el-radio-group v-model="ruleForm.giveaway_node" size="mini">
                <el-radio :label="1">确认收货后</el-radio>
                <el-radio :label="2">评价商品后</el-radio>
                <el-radio :label="3">过售后期后</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="参与商品类型" prop="participate_type">
              <el-radio-group
                v-model="ruleForm.participate_type"
                size="mini"
                @change="participate_typeWay"
              >
                <el-radio :label="1" border>全平台商品</el-radio>
                <el-radio :label="2" border>指定分类</el-radio>
                <el-radio :label="3" border>指定商品</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col v-if="ruleForm.participate_type == 2" :span="22">
            <el-form-item label="参与活动分类" prop="class_ids">
              <el-select
                v-model="classObj"
                style="width: 100%"
                filterable
                remote
                reserve-keyword
                placeholder="类目名称--(搜索前先选择时间段)"
                :remote-method="getClassListWay"
                :loading="goodsLoading"
                :disabled="domeTime.length==0"
                @change="hanldeSelectClassChange"
              >
                <el-option
                  v-for="item in classList"
                  :key="item.id"
                  :label="item.name"
                  :value="item"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-if="class_ids.length>0" label="分类赠送比例">
              <choosed-send-point-comp ref="choosedSendPointClassRef" :display="true" :list="class_ids" @deleteitem="handleDeleteClass" @updatelist="handleUpdateClassList" />
            </el-form-item>
          </el-col>

          <el-col v-if="ruleForm.participate_type == 3" :span="22">
            <el-form-item label="参与活动商品" prop="goods_ids">
              <el-select
                v-model="goodsObj"
                :multiple="false"
                style="width: 100%"
                filterable
                remote
                reserve-keyword
                placeholder="关键字查询支持商品名、ID、副标题、编码--(搜索前先选择时间段)"
                :remote-method="getGoodsListWay"
                :loading="goodsLoading"
                :disabled="domeTime.length==0"
                @change="hanldeSelectGoodsChange"
              >
                <el-option
                  v-for="item in GoodsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-if="goods_ids.length>0" label="商品赠送比例">
              <choosed-send-point-comp ref="choosedSendPointGoodsRef" :display="true" :list="goods_ids" @deleteitem="handleDeleteGoods" @updatelist="handleUpdateGoodsList" />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="submitForm('ruleForm')"
        >{{ activityId?'修 改':'确 定' }}</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :close-on-click-modal="false"
      title="查看商品"
      :visible.sync="goodsLookDialog"
      width="800px"
    >
      <el-row :gutter="20">
        <el-table
          v-loading="goodsLookLoading"
          :header-cell-style="{
            'background-color': '#f3f8fe',
            color: '#606266',
            height: '50px',
          }"
          highlight-current-row
          :data="GoodsDataList"
          style="width: 100%"
        >
          <el-table-column align="center" prop="id" label="id" />
          <el-table-column align="center" prop="name" label="商品名称" />
          <el-table-column align="center" prop="main_image" label="主图">
            <template slot-scope="scope">
              <el-image
                v-if="scope.row.main_image"
                style="width: 50px"
                :src="scope.row.main_image"
              />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="subtitle" label="副标题" />
        </el-table>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
  import LogoUpload from "@/components/FileUpload";
import {
  getBonusList,
  addBonus,
  getLoveFarmerGoodsList,
  delBonus,
  editStatusRestitution,
  getBonusDetail,
  getCateList,
  editBonus
} from '@/api/activity/agriculture'
import { getActivityGoodsList } from '@/api/index'
import ChoosedSendPointComp from './components/ChoosedSendPointComp.vue'

export default {
  name: 'SendPoint',
  components: { ChoosedSendPointComp,LogoUpload },
  data() {
    const domeValidator = (rule, value, callback) => {
      if (this.domeTime.length === 0) {
        return callback(new Error('请选择时间段'))
      } else {
        callback()
      }
    }
    const goodsIdsValidator = (rule, value, callback) => {
      if (this.goods_ids.length === 0) {
        return callback(new Error('请选择参与商品'))
      } else {
        callback()
      }
    }
    const classIdsValidator = (rule, value, callback) => {
      if (this.class_ids.length === 0) {
        return callback(new Error('请选择商品分类'))
      } else {
        callback()
      }
    }
    const defaultGiftRatioValidator = (rule, value, callback) => {
      if (value > 100) {
        return callback(new Error('默认赠送比例最大为100'))
      } else if (value < 0) {
        return callback(new Error('默认赠送比例不能小于零'))
      } else {
        callback()
      }
    }
    return {
      activityId: '',
      loading: false,
      searchForm: {
        activity_name: '',
        count: 10,
        page: 1,
        status: ''
      },
      // 列表数组
      dataList: [],
      // 列表总条数
      total: 0,
      // 添加修改弹框标题
      title: '添加活动',
      // 添加修改弹框控制器
      dialogVisible: false,
      // 添加修改弹框加载控制器
      submitLoading: false,
      // 添加修改提交的表单
      ruleForm: {
        image:'',
        activity_name: '',
        start_time: '',
        end_time: '',
        status: 2,
        participate_type: 1,
        default_gift_ratio: '',
        giveaway_node: 1,
        bonus: []
      },
      // {
      //       union_id: "",
      //       gift_ratio: "",
      //     },
      // 时间段回显
      domeTime: [],
      // 活动商品回显
      goods_ids: [],
      // 活动分类回显
      classObj: {},
      class_ids: [],
      goodsObj: {},
      // 添加修改表单验证规则
      rules: {
        explain: [{
          required: true,
          validator: (rule, value, callback) => {
            if (!value) {
              return callback(new Error("请输入活动说明"));
            } else {
              callback();
            }
          },
          trigger: "blur",
        }, ],
        images: [{ required: true, message: '请上传活动海报', trigger: 'blur' }],
        activity_name: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (!value) {
                return callback(new Error('请输入活动名称'))
              } else if (value.length > 20) {
                return callback(new Error('活动名称最多20个字'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        status: [{ required: true, message: '请选择状态', trigger: 'blur' }],
        domeTime: [{ required: true, validator: domeValidator, trigger: 'blur' }],
        default_gift_ratio: [
          { required: true, message: '请输入默认比例', trigger: 'blur' },
          {
            required: true, validator: defaultGiftRatioValidator, trigger: 'change'
          }
        ],
        giveaway_node: [{ required: true, message: '请选择赠送节点', trigger: 'blur' }],
        participate_type: [{ required: true, message: '请选择参与商品类型', trigger: 'blur' }],
        goods_ids: [{ required: true, validator: goodsIdsValidator, trigger: 'blur' }],
        class_ids: [{ required: true, validator: classIdsValidator, trigger: 'blur' }]
      },
      // 动态商品搜索的参数
      goodsSaerch: {
        keywords: '',
        page: 1,
        count: 20
      },
      // 动态获取的商品列表
      GoodsList: [],
      // 动态搜索需要用到加载控制器
      goodsLoading: false,
      // 动态分类搜索的参数
      classSaerch: {
        keywords: '',
        page: 1,
        count: 20
      },
      // 动态获取的分类列表
      classList: [],
      // 查看商品弹框控制器
      goodsLookDialog: false,
      goodsLookLoading: false,
      // 查看商品的商品列表
      GoodsDataList: [],
      poster:{}
    }
  },
  created() {
    this.getListWay()
  },
  methods: {
    // 上传邀请海报回调
    posterBack(file) {
      this.poster = file;
      this.ruleForm.image = file.url;
    },
    // 获取列表的函数
    getListWay() {
      this.loading = true
      getBonusList(this.searchForm)
        .then((res) => {
          this.loading = false
          this.dataList = res.data.list
          this.total = res.data.total
        })
        .catch((err) => {
          this.loading = false
          this.$messages.error(err.msg)
        })
    },
    // 重置搜索列表的函数
    resetting() {
      this.searchForm = {
        activity_name: '',
        count: 10,
        page: 1,
        status: ''
      }
      this.getListWay()
    },
    // 点击添加活动的函数
    addWay() {
      this.handleClose()
      this.title = '添加活动'
      this.dialogVisible = true
    },
    // 点击删除的函数
    delWay(row) {
      this.loading = true
      delBonus({ id: row.id })
        .then(() => {
          this.$messages.success('删除成功')
          this.getListWay()
        })
        .catch((err) => {
          this.loading = false
          this.$messages.error(err.msg)
        })
    },
    // 点击修改的函数
    emitWay(row) {
      this.activityId = row.id
      this.dialogVisible = true
      this.submitLoading = true
      getBonusDetail({ id: row.id })
        .then((res) => {
          this.posterBack({ url: res.data.image });
          this.ruleForm.activity_name = res.data.activity_name
          this.ruleForm.explain = res.data.explain
          this.ruleForm.status = res.data.status
          this.domeTime = [res.data.start_time, res.data.end_time]
          this.ruleForm.default_gift_ratio = res.data.default_gift_ratio
          this.ruleForm.giveaway_node = res.data.giveaway_node
          this.ruleForm.participate_type = res.data.participate_type
          if (this.ruleForm.participate_type === 2) {
            res.data.bonus.forEach(item => {
              this.$set(item, 'isUpdate', false)
            })
            this.class_ids = res.data.bonus
          } else if (this.ruleForm.participate_type === 3) {
            res.data.bonus.forEach(item => {
              this.$set(item, 'isUpdate', false)
            })
            this.goods_ids = res.data.bonus
          }
          this.submitLoading = false
        })
        .catch((err) => {
          this.submitLoading = false
          this.dialogVisible = false
          this.$messages.error(err.msg)
        })
    },
    // 单独修改列表某条数据状态的函数

    saveStatus(row) {
      var obj = {
        id: row.id,
        action: 'bonus'
      }
      this.loading = true
      editStatusRestitution(obj)
        .then((res) => {
          this.$messages.success(res.msg)
          this.getListWay()
        })
        .catch((err) => {
          this.$messages.error(err.msg)
          this.loading = false
        })
    },
    // 添加修改表单提交的函数
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.ruleForm.start_time = this.domeTime[0]
          this.ruleForm.end_time = this.domeTime[1]
          const bonus = []
          if (this.ruleForm.participate_type === 1) {
            delete this.ruleForm.bonus
            if (Number(this.ruleForm.default_gift_ratio) === 0) {
              this.$message.warning('当选择全平台商品时，默认赠送比例不能为0')
              return
            }
          } else if (this.ruleForm.participate_type === 2) {
            this.class_ids.forEach(item => {
              if (this.activityId) {
                if (item.union_id) {
                  bonus.push({
                    id: item.id,
                    activity_id: this.activityId,
                    union_id: item.union_id,
                    gift_ratio: item.gift_ratio
                  })
                } else {
                  bonus.push({
                    activity_id: this.activityId,
                    union_id: item.id,
                    gift_ratio: item.gift_ratio
                  })
                }
              } else {
                if (item.union_id) {
                  bonus.push({
                    id: item.id,
                    union_id: item.union_id,
                    gift_ratio: item.gift_ratio
                  })
                } else {
                  bonus.push({
                    union_id: item.id,
                    gift_ratio: item.gift_ratio
                  })
                }
              }
            })
          } else if (this.ruleForm.participate_type === 3) {
            this.goods_ids.forEach(item => {
              if (this.activityId) {
                if (item.union_id) {
                  bonus.push({
                    id: item.id,
                    activity_id: this.activityId,
                    union_id: item.union_id,
                    gift_ratio: item.gift_ratio
                  })
                } else {
                  bonus.push({
                    activity_id: this.activityId,
                    union_id: item.id,
                    gift_ratio: item.gift_ratio
                  })
                }
              } else {
                if (item.union_id) {
                  bonus.push({
                    id: item.id,
                    union_id: item.union_id,
                    gift_ratio: item.gift_ratio
                  })
                } else {
                  bonus.push({
                    union_id: item.id,
                    gift_ratio: item.gift_ratio
                  })
                }
              }
            })
          }
          this.ruleForm.bonus = bonus
          console.log('规整后的数据 this.ruleForm==>', this.ruleForm)
          let api = null
          if (this.activityId) {
            api = editBonus
            this.ruleForm.id = this.activityId
          } else {
            api = addBonus
          }
          this.submitLoading = true
          api(this.ruleForm)
            .then((res) => {
              this.handleClose()
              this.dialogVisible = false
              this.submitLoading = false
              this.$messages.success(res.msg)
              this.getListWay()
            })
            .catch((res) => {
              this.handleClose()
              this.submitLoading = false
              this.dialogVisible = false
              this.$messages.error(res.toString())
            })
        } else {
          return false
        }
      })
    },
    // 添加修改弹框关闭的函数
    handleClose() {
      this.ruleForm = {

        activity_name: '',
        start_time: '',
        end_time: '',
        status: 2,
        participate_type: 1,
        default_gift_ratio: '',
        giveaway_node: 1,
        bonus: []
      }
      this.classObj = {}
      this.goodsObj = {}
      this.domeTime = []
      this.goods_ids = []
      this.class_ids = []
      this.activityId = ''
    },
    // 选择参与商品类型发生改变的函数
    participate_typeWay(val) {},
    // 动态获取商品列表的函数
    getGoodsListWay(query) {
      this.goodsLoading = true
      if (query !== '') {
        this.goodsSaerch.keywords = query
      }
      var obj = {
        ...this.goodsSaerch,
        action: 'bonus',
        start_time: this.domeTime[0],
        end_time: this.domeTime[1]
      }
      getActivityGoodsList(obj)
        .then((res) => {
          this.goodsLoading = false
          this.GoodsList = res.data.list
        })
        .catch((err) => {
          this.$messages.error(err.msg)
          this.goodsLoading = false
        })
    },
    // 动态获取分类的函数
    getClassListWay(query) {
      this.goodsLoading = true
      if (query !== '') {
        var obj = {
          keywords: query,
          start_time: this.domeTime[0],
          end_time: this.domeTime[1]
        }
        getCateList(obj)
          .then((res) => {
            this.goodsLoading = false
            this.classList = res.data
          })
          .catch((err) => {
            this.$messages.error(err.msg)
            this.goodsLoading = false
          })
      }
    },
    // 查看商品列表的函数
    lookGoodsWay(row) {
      this.goodsLookDialog = true
      this.goodsLookLoading = true
      getLoveFarmerGoodsList({ activity_id: row.id })
        .then((res) => {
          this.GoodsDataList = res.data
          this.goodsLookLoading = false
        })
        .catch((err) => {
          this.goodsLookLoading = false
          this.goodsLookDialog = false
          this.$messages.error(err.msg)
        })
    },
    // 列表分页的函数
    handleSizeChange(val) {
      this.searchForm.count = val
      this.getListWay()
    },
    // 列表分页的函数
    handleCurrentChange(val) {
      this.searchForm.page = val
      this.getListWay()
    },
    // 分类选择改变时
    hanldeSelectClassChange(val) {
      console.log('val===>', val)
      const item = this.class_ids.find(item => {
        if (!item.union_id) {
          return item.id === val.id
        } else {
          return item.union_id === val.id
        }
      })
      if (item) {
        this.$message.warning('该分类已经选择！')
        return
      }
      this.$set(val, 'isUpdate', true)
      this.class_ids.push(val)
    },
    // 更新已经选择的分类
    handleUpdateClassList(row) {
      let item = this.class_ids.find(item => {
        if (row.union_id) {
          return item.union_id === row.union_id
        } else {
          if (!item.union_id) {
            return item.id === row.id
          }
        }
      })
      if (item) {
        item = row
      }
    },
    // 删除已经选择的分类
    handleDeleteClass(row) {
      this.class_ids = this.class_ids.filter(item => {
        if (row.union_id) {
          return item.union_id !== row.union_id
        } else {
          if (!item.union_id) {
            return item.id !== row.id
          }
        }
      })

      this.$refs.choosedSendPointClassRef.refreshList(this.class_ids)
    },
    // 商品选择改变时
    hanldeSelectGoodsChange(val) {
      console.log('val==>', val)
      const item = this.goods_ids.find(item => {
        if (!item.union_id) {
          return item.id === val.id
        } else {
          return item.union_id === val.id
        }
      })
      if (item) {
        this.$message.warning('该商品已经选择！')
        return
      }
      this.$set(val, 'isUpdate', true)
      this.goods_ids.push(val)
    },
    // 更新已经选择的商品
    handleUpdateGoodsList(row) {
      let item = this.goods_ids.find(item => {
        if (row.union_id) {
          return item.union_id === row.union_id
        } else {
          if (!item.union_id) {
            return item.id === row.id
          }
        }
      })
      if (item) {
        item = row
      }
    },
    // 删除已经选择的商品
    handleDeleteGoods(row) {
      this.goods_ids = this.goods_ids.filter(item => {
        if (row.union_id) {
          return row.union_id !== item.union_id
        } else {
          if (!item.union_id) {
            return row.id !== item.id
          }
        }
      })
      this.$refs.choosedSendPointGoodsRef.refreshList(this.goods_ids)
    }
  }
}
</script>

<style lang="scss" scoped>
.splitTitle {
  font-size: 16px;
  font-weight: 700;
  color: #606266;

  .split {
    width: 95%;
    border-bottom: 2px solid #c9c9c980;
    padding-bottom: 10px;
    margin: 20px auto;
  }
}
</style>
<style>
.el-upload--picture-card {
  width: 90px !important;
  height: 90px !important;
  line-height: 90px;
}

.el-upload-list--picture-card .el-upload-list__item-actions {
  width: 90px !important;
  height: 90px !important;
}

.el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 90px !important;
  height: 90px !important;
}

.el-upload-list--picture-card .el-upload-list__item {
  width: 90px !important;
  height: 90px !important;
}

.tox .tox-dialog-wrap__backdrop {
  z-index: 9993 !important;
}

.tox-tinymce-aux {
  z-index: 9990 !important;
}

.tox .tox-dialog {
  z-index: 9995 !important;
}
</style>
